package recursion;

import java.util.Scanner;

public class FeiBoNaQi {
    public static void main(String[] args) {
        while (true) {
            System.out.print("输入整数n，求第n个斐波那契数：");
            int n = new Scanner(System.in).nextInt();
            long result = f(n);
            System.out.printf("第%d个斐波那契数是：%d\n", n, result);
        }
    }

    private static long f(int n) {
        if (n < 1) {
            return 0;
        }
        if (n == 1 || n == 2) {
            return 1;
        }
        return f(n-1) + f(n-2);
    }
}
